package cn.javase.base.proxy;

import java.lang.reflect.Proxy;

/**
 * 代理工具类
 */
public class ProxyUtil {
    public static Star createProxy(Star star) {
        Object starProxy = Proxy.newProxyInstance(
                ProxyUtil.class.getClassLoader(),
                new Class[]{Star.class},
                (proxy, method, args) -> {
                    System.out.println("我在代理~");
                    return method.invoke(star, args);
                });
        return (Star)starProxy;
    }
}
